package com.example.zydraw;

import android.app.Dialog;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SeekBar;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.zydraw.draw.PaintRecord;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;

public class EditPaintDialogFragment extends BottomSheetDialogFragment {


    PaintRecord paintRecord;
    PaintCallback paintCallback;

    public EditPaintDialogFragment(PaintRecord paintRecord, PaintCallback paintCallback) {
        this.paintRecord = paintRecord;
        this.paintCallback = paintCallback;
    }

    @Nullable
    @Override
    public Dialog getDialog() {
        return super.getDialog();
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_edit_paint_dialog_layout, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        SeekBar seekBar = view.findViewById(R.id.text_size_bar);
        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                paintRecord.setTextSize(i);
                update();
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });

        SeekBar strokeWidthBar = view.findViewById(R.id.stroke_width_bar);
        strokeWidthBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                paintRecord.setStrokeWidth(i);
                update();
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });
    }

    private void update(){
        paintCallback.update();
    }

    interface PaintCallback {
        void update();
    }
}
